# coding:utf-8

import base64
import pickle


class CookieSecret(object):
    """封装base64加密解密方法"""
    @staticmethod
    def dumps(data: any) -> str:
        """加密 str -> str"""
        data_bytes = pickle.dumps(data)
        data_bs4 = base64.b64encode(data_bytes)
        return data_bs4.decode()

    @staticmethod
    def loads(data: str or bytes):
        """解密"""
        data_bytes = base64.b64decode(data)
        data_pickle = pickle.loads(data_bytes)
        return data_pickle


if __name__ == '__main__':
    test_data = {"test_data": 5}
    ret = CookieSecret().dumps(test_data)
    print(type(ret), ret)
    ret = CookieSecret().loads(ret)
    print(type(ret), ret)
